package com.jjlin.chapter_8;
import java.util.*;

public class CD10{
    public static void changeArr(int[] arr){
        int len = arr.length;
        for(int i = 0; i < len; i++)
            arr[i] = arr[i] != 0 ? (arr[i] / Math.abs(arr[i])) : arr[i];

    }

    public static int getMaxLength(int[] arr, int k){
        if(arr == null || arr.length == 0)
            return 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        map.put(0, -1);
        int sum = 0;
        int len = 0;
        for(int i = 0; i < arr.length; i++){
            sum += arr[i];
            if(map.containsKey(sum - k))
                len = Math.max(len, i - map.get(sum - k));
            if(!map.containsKey(sum))
                map.put(sum, i);
        }
        return len;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
            arr[i] = sc.nextInt();
        changeArr(arr);
        System.out.print(getMaxLength(arr, 0));
    }
}

